﻿//-----------------------------------------------------------------------
// <copyright file="GroupFilterSelection.cs" company="AFS">
// Copyright (c) AFS. All rights reserved.
//
//    This file is part of Chatbox.
//
//    Chatbox is free software: you can redistribute it and/or modify
//    it under the terms of the GNU Lesser General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    any later version.
//
//    Chatbox is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//    GNU Lesser General Public License for more details.
//
//    You should have received a copy of the GNU Lesser General Public License
//    along with Chatbox. If not, see http://www.gnu.org/copyleft/lesser.html
// </copyright>
//----------------------------------------------------------------------- 

namespace ChatBox.UI.MessageFilters
{
    using DomainObjects.XmlFeedObjects;

    /// <summary>
    /// Selection for filtering private messages by group
    /// </summary>
    public class GroupFilterSelection
    {
        /// <summary>
        /// Initializes a new instance of the GroupFilterSelection class with a filter type
        /// </summary>
        /// <param name="groupFilterType">The type to use</param>
        public GroupFilterSelection(GroupFilterType groupFilterType)
        {
            this.GroupFilterType = groupFilterType;
            this.Link = null;
        }

        /// <summary>
        /// Initializes a new instance of the GroupFilterSelection class with a link to a group
        /// </summary>
        /// <param name="link">the group link</param>
        public GroupFilterSelection(Link link)
        {
            this.GroupFilterType = GroupFilterType.ShowMessagesToGroup;
            this.Link = link;
        }

        /// <summary>
        /// Gets or sets the type of filtering
        /// </summary>
        public GroupFilterType GroupFilterType { get; set; }

        /// <summary>
        /// Gets or sets the group to filter on
        /// </summary>
        public Link Link { get; set; }

        /// <summary>
        /// Gets the node id of the group, or zero if there is none
        /// </summary>
        public int NodeId
        {
            get
            {
                if (this.Link == null)
                {
                    return 0;
                }
                    
                return Link.NodeId;
            }
        }

        /// <summary>
        /// Gets the text to display in the dropdown
        /// </summary>
        /// <returns></returns>
        public string DisplayText
        {
            get
            {
                switch (this.GroupFilterType)
                {
                    case GroupFilterType.Unknown:
                        return "  Unknown";

                    case GroupFilterType.ShowAllMessages:
                        return " All messages";

                    case GroupFilterType.ShowAllMessagesNotToAnyGroup:
                        return " Messages not to any group";

                    case GroupFilterType.ShowAllMessagesToAnyGroup:
                        return " Messages to any group";

                    case GroupFilterType.ShowMessagesToGroup:
                    {
                        if (this.Link == null)
                        {
                            return "  Missing group";
                        }

                        return this.Link.Text;
                    }

                    default:
                        return "  Invalid Filter type";
                }
            }
        }
    }
}
